package com.svconnect.plugin.model.wsdl;

import java.util.LinkedList;
import java.util.List;

public class ComplexDataType extends SimpleDataType implements IDataType {

	private List<Parameter> members = new LinkedList<Parameter>();
	private EComplexType type = EComplexType.CUSTOM;
	private ComplexDataType baseType = null; 
	private String namespace = null;

	public String getNamespace() {
		return namespace;
	}

	public void setNamespace(String namespace) {
		this.namespace = namespace;
	}

	public void addMember(Parameter elem) {
		this.members.add(elem);
	}
	
	public void removeMember(Parameter elem) {
		this.members.remove(elem);
	}
	
	public List<Parameter> getMembers() {
		return members;
	}	
	public void setMembers(List<Parameter> members) {
		this.members = members;
	}	
	
	public EComplexType getType() {
		return type;
	}

	public void setType(EComplexType type) {
		this.type = type;
	}
	
	public ComplexDataType getBaseType() {
		return baseType;
	}

	public void setBaseType(ComplexDataType baseType) {
		this.baseType = baseType;
	}
	
	@Override
	public String toString() {
		switch(type) {
			case DICTIONARY:
				IDataType keyType = null;
				IDataType valType = null;
				ComplexDataType keyValPair = (ComplexDataType)members.get(0).getType();
				for(Parameter p : keyValPair.getMembers()) {
					if (p.getName().equals("Key"))
						keyType = p.getType();
					else if (p.getName().equals("Value"))
						valType = p.getType();
				}
				return String.format("java.util.Map<%s,%s>", keyType, valType);
			case SEQUENCE:
				return String.format("java.util.List<%s>", members.get(0).getType());
			default:
				return this.getName();
		}
	}
	
	public ComplexDataType copy() {
		ComplexDataType du = new ComplexDataType();
		du.setName(getName());
		du.setNamespace(getNamespace());
		du.setBaseType(getBaseType());
		du.setNullable(isNullable());
		du.setType(getType());
		du.setMembers(getMembers());
		return du;
	}
	
	
}
 


